//This 2d3d browser use the chrome module and mouse and keyboard inputs are working in this one.
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )

function reset_ent()
	RunConsoleCommand("lua_reloadent_sv", "google")
	RunConsoleCommand("lua_reloadent_cl", "google")
end

concommand.Add("chr_reset", reset_ent)



function ENT:Initialize()
	self.Entity:SetModel("models/props/cs_office/tv_plasma.mdl")

	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetCollisionGroup( 0 )
	self.Entity:DrawShadow( false )

	local phys = self:GetPhysicsObject()

	if IsValid( phys ) then
		phys:EnableMotion( false )
	end
	self.NextUse = 0
	self:NString("URL", "http://www.google.com/")

	if WireAddon then
		self.Inputs = WireLib.CreateSpecialInputs(self.Entity, {"Hide URL Bar","URL"}, {"NORMAL","STRING"})
		--self.Outputs = WireLib.CreateSpecialOutputs( self.Entity, {"URL"}, {"STRING"})
	end


end

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end

	local SpawnPos = tr.HitPos + tr.HitNormal * 16

	local ent = ents.Create( "google" )
	local ang = ply:GetAimVector():Angle(); ang.p = 0; ang.r = 0; ang.y = (ang.y+180) % 360
	ent:SetPos( SpawnPos )
	ent:SetAngles(ang)
	ent:Spawn()
	ent:Activate()

	return ent
end

function ENT:SynURL(url)
end

function ENT:Think()
	if WireAddon then
		--Wire_TriggerOutput(self.Entity, "URL", self.LoadedSvURL)
	end

	self.Entity:NextThink(CurTime()+0.01)
	return true
end

function ENT:Use( ply )

	if CurTime() < self.NextUse then return end
	self.NextUse = CurTime() + 0.2
end

function ENT:OnRestore()
	Wire_Restored(self.Entity)
end

function ENT:TriggerInput(iname, value)
	if(iname == "URL") then
		if(value and value ~= "") then
			self:NString("URL", value)
		end
	elseif(iname == "Hide URL Bar") then
		if(value and value ~= 0) then
			self:NBool("ShowURL", true)
		else
			self:NBool("ShowURL", false)
		end
	end
end